package com.mioto.ld.communication.mqtt.protocol;

import com.mioto.ld.communication.mqtt.protocol.cache.ReportAttributeCache;
import com.mioto.ld.communication.mqtt.protocol.model.Message;
import com.mioto.ld.communication.mqtt.protocol.model.device.DeviceDataReportPayload;
import com.mioto.ld.utils.SpringBeanUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Executor;

/**
 * @author mioto-qinxj
 * @date 2024/5/15
 * @desc
 */
@Slf4j
public class ReportHandleStrategy implements IReceiptHandleStrategy {
    private AttrReportTriggerHandler attrReportTriggerHandler;
    public ReportHandleStrategy(){
        attrReportTriggerHandler = new AttrReportTriggerHandler();
    }
    @Override
    public void protocolHandler(Message message)  throws Exception{
        log.info("=============device attribute report,check alert config and linkage trigger=============");
        //将对应的属性存放到缓存之中
        DeviceDataReportPayload payload = (DeviceDataReportPayload) message.getMessageBody().getPayload();
        ReportAttributeCache.put(message.getSn(), payload.getAttribute());
        attrReportTriggerHandler.handle(message);
    }
}
